package com.oscar.ehome.presenter;

import android.util.Log;

import com.oscar.ehome.bean.loginbean.idcardbean.ComitMessageBean;
import com.oscar.ehome.bean.loginbean.idcardbean.IdBean;
import com.oscar.ehome.bean.loginbean.idcardbean.IdCardBean;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.view.loginview.view.SubcomitMessageView;

import java.io.File;
import java.util.Map;

/**
 * Created by author 孟琬和
 * on 2017/6/25.
 * 上传个人信息
 */

public class SubcomitPresenter {

    SubcomitMessageView view;
    HttpModel httpModel;

    public SubcomitPresenter(SubcomitMessageView view) {
        this.view = view;
        httpModel = new HttpModelImple();
    }

    /**
     * 上传个人信息到本地服务器
     *
     * @param token
     */
    public void upload(String name, String sex, String idcardnumber, String img, String idcardname, String token) {
        httpModel.uploadmessage(name, sex, idcardnumber, img, idcardname, token, new OnHttpListener<ComitMessageBean>() {
            @Override
            public void onSuccess(ComitMessageBean obj) {
                if (view != null)
                    view.uoloadmessage(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
                Log.e("1111", "onError: "+msg );
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }

    /**
     * 认证平台验证
     *
     * @param map
     * @param file
     */
    public void ocidcard(Map<String, String> map, File file) {
        httpModel.approveId(map, file, new OnHttpListener<IdBean>() {

            @Override
            public void onSuccess(IdBean obj) {
                if (view != null)
                    view.approveid(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
                Log.e("1111111", "onError: "+msg );
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }

    /**
     * 上传头像到本地服务器
     *
     * @param token
     * @param file
     */
    public void approveidcard(String token, String imgname, File file) {
        httpModel.approve(token, imgname, file, new OnHttpListener<IdCardBean>() {

            @Override
            public void onSuccess(IdCardBean obj) {
                if (view != null)
                    view.approvecard(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
                Log.e("1111111111", "onError: "+msg );
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }


}
